package 第十一章_网络编程.第十一章_网络编程_MINA;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

public class MinaServerHandler extends IoHandlerAdapter {
    @Override
    //一次对话被打开
    public void sessionOpened(IoSession session) throws Exception {
        super.sessionOpened(session);
        System.out.println("welcome client "+session.getRemoteAddress());
    }
    //会话关闭
    @Override
    public void sessionClosed(IoSession session) throws Exception {
        super.sessionClosed(session);
        System.out.println("client closed");
    }
    //接收消息
    @Override
    public void messageReceived(IoSession session, Object message) throws Exception {
        super.messageReceived(session, message);
        //1.文本 2.对象
        //String msg=(String) message;
        Message msg=(Message) message;
        System.out.println("收到客户端发来的消息: "+msg.toString());
        msg.setInfo("服务器发送的消息填写处");
        session.write(msg);
    }
}
